﻿using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using UFIDA.U9.WSS.ProxyService.Behavior.WebHttp.Base;

namespace UFIDA.U9.WSS.ProxyService.Behavior.WebHttp
{
    public class ContextProxyServiceBehavior : NewtonsoftJsonBehavior
    {
        private readonly string _accessGroup;
        private readonly bool _accessProxy;
        private readonly bool _contextNeedUserPassword;
        private readonly bool _useDataContract;

        public ContextProxyServiceBehavior(bool useDataContract = false, bool accessProxy = false,
            string accessGroup = "",
            bool contextNeedUserPassword = false)
        {
            _useDataContract = useDataContract;
            _accessProxy = accessProxy;
            _accessGroup = accessGroup;
            _contextNeedUserPassword = contextNeedUserPassword;
        }

        protected override IDispatchMessageFormatter GetCustomDispatchFormatter(
            OperationDescription operationDescription)
        {
            return new ContextProxyServiceDispatchFormatter(operationDescription, _useDataContract, _accessProxy,
                _accessGroup,
                _contextNeedUserPassword);
        }
    }
}